package com.yinhe.music.yhmusic.recent.adapter;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.yinhe.music.yhmusic.R;
import com.yinhe.music.yhmusic.constants.IConstants;
import com.yinhe.music.yhmusic.db.DataBaseAccessor;
import com.yinhe.music.yhmusic.db.bean.RecentMusicDBEntity;
import com.yinhe.music.yhmusic.downmusic.DownloadStatus;


/**
 * @author hasee
 * @date 2017/8/15
 */

public class RecentListAdapter extends BaseQuickAdapter<RecentMusicDBEntity, BaseViewHolder> {

    public RecentListAdapter() {
        super(R.layout.new_music_recyclerview_item);
    }

    @Override
    protected void convert(BaseViewHolder helper, RecentMusicDBEntity item) {
        helper.setText(R.id.playlist_song, item.getSongname())
                .setText(R.id.playlist_singer, item.getSingername());
        helper.addOnClickListener(R.id.playlist_more);

        if (DataBaseAccessor.getInstance().isExsitIdSyn(item.getSongid(), DownloadStatus.DOWNLOAD_STATUS_COMPLETED)) {
            item.setUri(DataBaseAccessor.getInstance().getDownMusicByDownloadIdSyn(item.getSongid()).getUri());
            DataBaseAccessor.getInstance().updateSong(item);
            helper.setGone(R.id.image_get, true);
        }

        if (DataBaseAccessor.getInstance().isExistSongDBId((int) item.getSongid())) {
            helper.setGone(R.id.image_local, true);
        } else {
            helper.setGone(R.id.image_local, false);
        }
    }
}
